package cn.eeepay.boss.action.workOrder;

import cn.eeepay.boss.system.DataSource;
import cn.eeepay.boss.system.SystemLog;
import cn.eeepay.framework.model.workOrder.WorkProductConfigEntity;
import cn.eeepay.framework.service.workOrder.WorkProductConfigService;
import cn.eeepay.framework.util.Constants;
import cn.eeepay.framework.util.ResultModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * 工单业务配置表
 *
 * @author quanhz
 * @email
 * @date 2020-08-20 09:01:59
 */
@RestController
@RequestMapping("/workProductConfig")
public class WorkProductConfigController {

    private Logger log = LoggerFactory.getLogger(WorkProductConfigController.class);

    @Autowired
    private WorkProductConfigService workProductConfigService;


    /**
     * 信息
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping("/info")
    public ResultModel info() {
        try {
            return ResultModel.ok().put("data", workProductConfigService.getDefaultconfig());
        } catch (Exception e) {
            log.error("获取工单业务配置信息失败", e);
            return ResultModel.error("获取工单业务配置信息失败");
        }

    }


    /**
     * 修改
     */
    @DataSource()
    @RequestMapping("/update")
    @SystemLog(description = "修改工单业务配置",operCode = "workProductConfig.update")
    public ResultModel update(@RequestBody WorkProductConfigEntity workProductConfig) {
        try {
            return workProductConfigService.updateById(workProductConfig);
        } catch (Exception e) {
            log.error("保存工单业务配置失败", e);
            return ResultModel.error("保存工单业务配置失败");
        }
    }

    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping("/checkOrderType")
    public ResultModel checkOrderType(String workTypeId) {
        try {
            return ResultModel.ok().put("shoushuaFlag", workProductConfigService.checkOrderType(workTypeId));
        } catch (Exception e) {
            log.error("判断工单类型是否首刷失败", e);
            return ResultModel.error("判断工单类型是否首刷失败");
        }
    }



}
